package com.shiliao.app.manager.entity;

import android.text.TextUtils;

import com.yimei.framework.base.serializer.JSONKey;
import com.yimei.framework.mvp.entity.BaseEntity;
import com.yimei.framework.util.SystemUtils;

/**
 * 用户类,包含用户所有属性
 * 可添加到此类，jsonkey添加可以多个
 * Created by yjl on 2017/7/11.
 */

public class UserEntity extends BaseEntity {

    @JSONKey(keys = "user_id", type = String.class)
    public String mUserId;//用户id


    @JSONKey(keys = {"password"}, type = String.class)
    public String mPassWord;//用户密码

    @JSONKey(keys = "mobile", type = String.class)
    public String mobile;
    @JSONKey(keys = "access_token", type = String.class)
    public String mAccessToken;//用户token

    @JSONKey(keys = {"mobile_type"}, type = String.class)
    public String MobileType = "android"; // 系统

    @JSONKey(keys = "device_no", type = String.class)
    public String mDeviceNo = SystemUtils.getUserDeviceID(); // 设备编号

    @JSONKey(keys = "userInfo", type = UserInfoEntity.class)
    public UserInfoEntity userInfo;


    // 极光推送的注册设备id
    @JSONKey(keys = {"regid"}, type = String.class)
    public String mRegisID = "";

    public String getmUserId() {
        return mUserId;
    }

    public void setmUserId(String mUserId) {
        this.mUserId = mUserId;
    }


    public String getmPassWord() {
        return mPassWord;
    }

    public void setmPassWord(String mPassWord) {
        this.mPassWord = mPassWord;
    }


    public String getmAccessToken() {
        return mAccessToken;
    }

    public void setmAccessToken(String mAccessToken) {
        this.mAccessToken = mAccessToken;
    }

    public String getMobileType() {
        return MobileType;
    }

    public void setMobileType(String mobileType) {
        MobileType = mobileType;
    }

    public String getmDeviceNo() {
        return mDeviceNo;
    }

    public void setmDeviceNo(String mDeviceNo) {
        this.mDeviceNo = mDeviceNo;
    }

    public String getmRegisID() {
        return mRegisID;
    }

    public void setmRegisID(String mRegisID) {
        this.mRegisID = mRegisID;
    }


    public UserInfoEntity getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfoEntity userInfo) {
        this.userInfo = userInfo;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * 判断是否为同一个UserModel对象
     *
     * @param entity
     * @return true or false
     */
    public boolean equals(UserEntity entity) {
        if (entity == null) {
            return false;
        }
        try {
            if (this.mUserId.equals(entity.mUserId)
                    && this.getUserInfo() != null
                    && entity.getUserInfo() != null) {
                if (this.userInfo.getIdname().equals(entity.userInfo.getIdname())
                        && this.mAccessToken.equals(entity.mAccessToken)
                        && this.userInfo.getMobile_number().equals(entity.getUserInfo().getMobile_number())
                        && this.userInfo.getIdcard().equals(entity.getUserInfo().getIdcard())
                        && this.getUserInfo().getPortrait_path().equals(entity.getUserInfo().getPortrait_path())
                        && this.mDeviceNo.equals(entity.mDeviceNo)
                        && this.mPassWord.equals(entity.mPassWord)
                        && this.MobileType.equals(entity.MobileType)
                        && this.mRegisID.equals(entity.mRegisID)) {
                    return true;
                }
            }
        } catch (Exception e) {
            return false;
        }

        return false;
    }

    /**
     * 判断是否是同一个用户，只根据User id 判断
     *
     * @param entity
     * @return
     */
    public boolean isSameUser(UserEntity entity) {
        if (entity == null || TextUtils.isEmpty(entity.mUserId)) {
            return false;
        }
        if (!TextUtils.isEmpty(entity.mUserId) && this.mUserId.equals(entity.mUserId)) {
            return true;
        }
        return false;
    }
}
